﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Revis.VClinicNet.Core.Domain
{
    public class Visit : IEquatable<Visit>
    {
        public virtual long Id { get; protected set; }
        public virtual Doctor Doctor { get; protected set; }
        public virtual Patient Patient { get; protected set; }
        public virtual DateTime Date { get; protected set; }

        public static readonly TimeSpan MinimumVisitTime = new TimeSpan(0, 5, 0);

        #region Constructors

        public Visit()
        {
        }

        public Visit(Doctor doctor, Patient patient, DateTime date) :
            this(0, doctor, patient, date)
        {
        }

        public Visit(long id, Doctor doctor, Patient patient, DateTime date)
        {
            if (doctor == null) {
                throw new ArgumentNullException("Null doctor");
            }
            if (patient == null) {
                throw new ArgumentNullException("Null patient");
            }
            Id = id;
            Doctor = doctor;
            Patient = patient;
            DateTime newDate = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, 0);
            Date = newDate;
        }

        #endregion

        #region Methods

        public override bool Equals(object obj)
        {
            return Equals(obj as Visit);
        }

        public virtual bool Equals(Visit visit)
        {
            if (visit == null) {
                return false;
            }
            return this.Id == visit.Id;
        }

        public override int GetHashCode()
        {
            return Id.GetHashCode() ^ base.GetHashCode();
        }

        #endregion


    }
}
